package 华为OD机试B卷复用题.基础题;

import utils.MyUtil;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class HJ14_求满足条件的最长子串的长度 {
    public static void main(String[] args) throws FileNotFoundException {
        Scanner in = new Scanner(new File("src/main/java/华为OD机试B卷复用题/基础题/input/14.txt"));
        MyUtil.START();
        Solution(in);
        MyUtil.END();
    }

    // 滑动窗口
    static void Solution(Scanner in) {
        String s = in.nextLine();
        int right = 0;
        int left = 0;
        int tmpSize = 1;
        int maxSize = -1;
        int alpha = 0;
        int digit = 0;
        if (Character.isAlphabetic(s.charAt(0))) {
            alpha++;
        } else {
            digit++;
        }
        String res = "";
        while (right < s.length()) {
            if (alpha > 1) {
                while (alpha > 1) {
                    if (Character.isAlphabetic(s.charAt(left))) {
                        alpha--;
                    } else {
                        digit--;
                    }
                    left++;
                    tmpSize--;
                }
            }
            if (digit > 0 && alpha == 1 && tmpSize > maxSize) {
                maxSize = tmpSize;
                res = s.substring(left, right + 1);
            }
            if (right == s.length() - 1) {
                break;
            }
            right++;
            tmpSize++;
            if (Character.isAlphabetic(s.charAt(right))) {
                alpha++;
            } else {
                digit++;
            }
        }
        System.out.println(maxSize);
        System.out.println(res);
    }
}
